package com.wlyuan.open.domain.source;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import com.wlyuan.open.OpenBaseSyncDTO;
import com.wlyuan.open.dto.*;
import com.wlyuan.open.dto.tenant.OpenCompanyTenantSyncDTO;
import com.wlyuan.open.dto.tenant.OpenDriverTenantSyncDTO;
import com.wlyuan.open.dto.tenant.OpenTenantRelationSyncDTO;
import com.wlyuan.open.dto.top.OpenTopExtensionOrderSyncDTO;
import com.wlyuan.open.dto.transport.OpenTransportRelationSyncDTO;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yuanzheng
 */
@RequiredArgsConstructor
@Getter
public class SourceClass implements NamedValue<Integer> {
    private static final long serialVersionUID = -2587637248128145395L;
    private final Integer value;
    private final String name;
    private final Class<?> sourceClass;

    public static SourceClass CUSTOMER = new SourceClass(1, "客户信息", OpenCustomerSyncDTO.class);
    public static SourceClass CARRIER = new SourceClass(2, "承运方信息", OpenCarrierSyncDTO.class);
    public static SourceClass CONSIGNEE = new SourceClass(3, "收货方信息", OpenConsigneeSyncDTO.class);
    public static SourceClass GOODS = new SourceClass(4, "物品信息", OpenGoodsSyncDTO.class);
    public static SourceClass ORDER = new SourceClass(5, "订单信息", OpenOrderSyncDTO.class);
    public static SourceClass TRANSPORT = new SourceClass(6, "运单信息", OpenTransportSyncDTO.class);
    public static SourceClass RELATION = new SourceClass(7, "上下游关系", OpenRelationSyncDTO.class);
    public static SourceClass USER = new SourceClass(8, "用户信息", OpenUserSyncDTO.class);
    public static SourceClass TENANT = new SourceClass(9, "租户信息", OpenCompanyTenantSyncDTO.class);
    public static SourceClass TENANT_DRIVER = new SourceClass(9, "租户信息", OpenDriverTenantSyncDTO.class);
    public static SourceClass DRIVER = new SourceClass(10, "司机信息", OpenDriverSyncDTO.class);
    public static SourceClass VEHICLE = new SourceClass(11, "车辆信息", OpenVehicleSyncDTO.class);
    public static SourceClass CONTRACT = new SourceClass(12, "合同信息", OpenContractSyncDTO.class);
    public static SourceClass BILL = new SourceClass(13, "对账单", OpenBillSyncDTO.class);
    public static SourceClass TENANT_RELATION = new SourceClass(14, "租户邀请关系", OpenTenantRelationSyncDTO.class);
    public static SourceClass COMBINE = new SourceClass(19, "拼车单信息", OpenCombineSyncDTO.class);
    public static SourceClass TEMPLATE = new SourceClass(15, "合约信息", OpenTemplateSyncDTO.class);
    public static SourceClass QUOTATION = new SourceClass(16, "报价信息", OpenQuotationSyncDTO.class);
    public static SourceClass APY = new SourceClass(17, "收付款信息", OpenPaySyncDTO.class);
    public static SourceClass TOP_EXTENSION = new SourceClass(18, "top订单定制信息", OpenTopExtensionOrderSyncDTO.class);
    public static SourceClass TRANSPORT_RELATION = new SourceClass(20, "运单关系", OpenTransportRelationSyncDTO.class);
    public static SourceClass COMBINE_QUOTATION = new SourceClass(21, "合单报价", OpenCombineQuotationSyncDTO.class);

    private static Map<Class<?>, SourceClass> createClassMap() {
        Map<Class<?>, SourceClass> classMap = new HashMap<>(26);
        classMap.put(GOODS.getSourceClass(), GOODS);
        classMap.put(CUSTOMER.getSourceClass(), CUSTOMER);
        classMap.put(CONSIGNEE.getSourceClass(), CONSIGNEE);
        classMap.put(CARRIER.getSourceClass(), CARRIER);
        classMap.put(RELATION.getSourceClass(), RELATION);
        classMap.put(TRANSPORT.getSourceClass(), TRANSPORT);
        classMap.put(ORDER.getSourceClass(), ORDER);
        classMap.put(USER.getSourceClass(), USER);
        classMap.put(TENANT.getSourceClass(), TENANT);
        classMap.put(DRIVER.getSourceClass(), DRIVER);
        classMap.put(VEHICLE.getSourceClass(), VEHICLE);
        classMap.put(CONTRACT.getSourceClass(), CONTRACT);
        classMap.put(BILL.getSourceClass(), BILL);
        classMap.put(TENANT_DRIVER.getSourceClass(), TENANT_DRIVER);
        classMap.put(TENANT_RELATION.getSourceClass(), TENANT_RELATION);
        classMap.put(COMBINE.getSourceClass(), COMBINE);
        classMap.put(TEMPLATE.getSourceClass(), TEMPLATE);
        classMap.put(QUOTATION.getSourceClass(), QUOTATION);
        classMap.put(APY.getSourceClass(), APY);
        classMap.put(TOP_EXTENSION.getSourceClass(), TOP_EXTENSION);
        classMap.put(TRANSPORT_RELATION.getSourceClass(), TRANSPORT_RELATION);
        classMap.put(COMBINE_QUOTATION.getSourceClass(), COMBINE_QUOTATION);
        return classMap;
    }

    public static Map<Integer, SourceClass> MAP = new NamedValueMap<>(SourceClass.class);
    public static Map<Class<?>, SourceClass> CLASS_MAP = createClassMap();

    public static SourceClass fromValue(Integer value) {
        return MAP.get(value);
    }

    public static <T extends OpenBaseSyncDTO> SourceClass fromClass(T source) {
        return CLASS_MAP.get(source.getClass());
    }
}
